import Taro, { Component } from '@tarojs/taro'
import { View, Text, Camera, Button, Image, CoverImage, CoverView } from '@tarojs/components'
import { AtSearchBar } from 'taro-ui'

export default class Test extends Component {

  config = {
    navigationBarTitleText: 'test'
  }

  constructor () {
    super(...arguments)
    this.state = {
      src: '',
      isShow: true
    }
  }

  takePhoto() {
    console.log('点击拍照');
    let me = this;
    const ctx = Taro.createCameraContext()
    console.log(ctx);
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        console.log('success');
        me.setState({
          src: res.tempImagePath
        });
      },
      fail: (res) => {
        console.log('fail');
        console.log(res);
      },
      complete: (res) => {
        console.log('complete');
        console.log(res);
      }
    })
  }

  stop() {
    console.log('stop');
  }

  error() {
    console.log('error');
  }
 
  reset() {
    this.setState({
      src: ''
    });
  }

  render () {
    const tabList = [{ title: '标签页1' }, { title: '标签页2' }, { title: '标签页3' }]
    return (
      <View className='index'>
        <Camera devicePosition='front' flash='on' onStop={this.stop} onError={this.error} style='width:500rpx;height:500rpx;'>
          {/* {
            this.state.isShow
            &&
            <CoverImage src={src} ></CoverImage>
          } */}
          <CoverImage src={src} ></CoverImage>
        </Camera>
        <Button onClick={this.takePhoto}>拍照</Button>
        <Button onClick={this.reset}>重拍</Button>
        <View>预览</View>
      </View>
    )
  }
}

